<?php

/*
 * Funkce pro smazání povolené mailové adresy - vykreslí formulář
*/
function mailcontent_delmailaddress($mailaddress, $idacc) {
    global $user;
    if (user_access('settings accounts')) {
        $text = "<hr><br><br>".t('Do you wish delete')." "."<b><u>".$mailaddress."</u></b>"." ".t('for account')." "."<b><u>".$username."</b></u>"." ".t('from subscribers?');
        $GLOBALS['mailcontent_idacc'] = $idacc;
        $GLOBALS['mailcontent_mailaddress'] = $mailaddress;
        $GLOBALS['mailcontent_ret'] = 'mailboxes';
        $text = $text.drupal_get_form('mailcontent_settings_del_permision_for_mailaddress_form');
        $GLOBALS['mailcontent_idacc'] = '';
        $GLOBALS['mailcontent_mailaddress'] = '';
        $GLOBALS['mailcontent_ret'] = '';
    } else {
        $text = "<hr><br><br>".t("You have not permission for this action!");
        global $user;
        mailcontent_error_permissions("User ".$user->uid." has not permission");
    }
    return $text;
}  //OK

/*
 * Funkce pro editaci povolené mailové adresy - vykreslí formulář
*/
function mailcontent_editmailaddress($mailaddress, $idacc, $role) {
    global $user;
    if (user_access('settings accounts')) {
        $text = "<hr><br><br>";
        $GLOBALS['mailcontent_idacc'] = $idacc;
        $GLOBALS['mailcontent_mailaddress'] = $mailaddress;
        $GLOBALS['mailcontent_role'] = $role;
        $GLOBALS['mailcontent_ret'] = 'mailboxes';
        $text = $text.drupal_get_form('mailcontent_settings_edit_permision_for_mailaddress_form');
        $GLOBALS['mailcontent_idacc'] = '';
        $GLOBALS['mailcontent_mailaddress'] = '';
        $GLOBALS['mailcontent_role'] = '';
    } else {
        $text = "<hr><br><br>".t("You have not permission for this action!");
        global $user;
        mailcontent_error_permissions("User ".$user->uid." has not permission");
    }
    return $text;
} //OK

/*
 * Funkce pro smazání mailboxu - vykreslí formulář
*/
function mailcontent_dellogin($mailcontent_username, $idacc) {
    global $user;
    if (user_access('settings accounts')) {
        $text = "<hr><br><br>".t('Do you wish delete ')."<b><u>".$mailcontent_username."</u></b>".t(' from accounts?');
        $GLOBALS['mailcontent_idacc'] = $idacc;
        $GLOBALS['mailcontent_ret'] = 'accounts';
        $text = $text.drupal_get_form('mailcontent_settings_del_mail_form');
        $GLOBALS['mailcontent_idacc'] = '';
    } else {
        $text = "<hr><br><br>".t("You have not permission for this action!");
        global $user;
        mailcontent_error_permissions("User ".$user->uid." has not permission");
    }
    return $text;
} //OK

/*
 * Funkce pro editaci mailboxu - vykreslí formulář
*/
function mailcontent_editlogin($mailcontent_username, $idacc) {
    global $user;
    if (user_access('settings accounts')) {
        $text = "<hr><br><br>";
        $GLOBALS['mailcontent_idacc'] = $idacc;
        $GLOBALS['mailcontent_ret'] = 'accounts';
        $text = $text.drupal_get_form('mailcontent_settings_edit_mail_form');
        $text = $text.drupal_get_form('mailcontent_settings_passwd_mail_form');
        $GLOBALS['mailcontent_idacc'] = '';
    } else {
        $text = "<hr><br><br>".t("You have not permission for this action!");
        global $user;
        mailcontent_error_permissions("User ".$user->uid." has not permission");
    }
    return $text;
} //OK

/*
 * Funkce pro smazání akce - vykreslí formulář
*/
function mailcontent_delaction($mailcontent_ida) {
    global $user;
    if (user_access('settings actions')) {
        if (db_result(db_query("SELECT name FROM {mailcontent_actions} WHERE ida=".$mailcontent_ida))) {
            $result = (db_query("SELECT name FROM {mailcontent_actions} WHERE ida=".$mailcontent_ida));
            $row = db_fetch_array($result);
        }
        $text = "<hr><br><br>".t('Do you wish delete ')."<b><u>".$row['name']."</u></b>".t(' from actions?');
        $GLOBALS['mailcontent_ida'] = $mailcontent_ida;
        $GLOBALS['mailcontent_ret'] = 'actions';
        $text = $text.drupal_get_form('mailcontent_settings_del_action_form');
        $GLOBALS['mailcontent_ida'] = '';
    } else {
        $text = "<hr><br><br>".t("You have not permission for this action!");
        global $user;
        mailcontent_error_permissions("User ".$user->uid." has not permission");
    }
    return $text;
} //OK

/*
 * Funkce pro editaci akce - vykreslí formulář
*/
function mailcontent_editaction($mailcontent_ida) {
    global $user;
    if (user_access('settings actions')) {
        $text = "<hr><br><br>";
        $GLOBALS['mailcontent_ida'] = $mailcontent_ida;
        $GLOBALS['mailcontent_ret'] = 'actions';
        $text = $text.drupal_get_form('mailcontent_settings_edit_action_form');
        $GLOBALS['mailcontent_ida'] = '';
    } else {
        $text = "<hr><br><br>".t("You have not permission for this action!");
        global $user;
        mailcontent_error_permissions("User ".$user->uid." has not permission");
    }
    return $text;
} //OK

/*
 * Funkce pro smazání klíčového slova - vykreslí formulář
*/
function mailcontent_delkeyword($mailcontent_idw) {
    global $user;
    if (user_access('settings actions')) {
        if (db_result(db_query("SELECT keyword FROM {mailcontent_keywords} WHERE idw=".$mailcontent_idw))) {
            $result = (db_query("SELECT keyword FROM {mailcontent_keywords} WHERE idw=".$mailcontent_idw));
            $row = db_fetch_array($result);
        }
        $text = "<hr><br><br>".t('Do you wish delete')." <b><u>".$row['keyword']."</u></b> ".t('from keywords?');
        $GLOBALS['mailcontent_idw'] = $mailcontent_idw;
        $GLOBALS['mailcontent_ret'] = 'keywords';
        $text = $text.drupal_get_form('mailcontent_settings_del_keyword_form');
        $GLOBALS['mailcontent_idw'] = '';
    } else {
        $text = "<hr><br><br>".t("You have not permission for this action!");
        global $user;
        mailcontent_error_permissions("User ".$user->uid." has not permission");
    }
    return $text;
} //OK

/*
 * Funkce pro editaci klíčového slova - vykreslí formulář
*/
function mailcontent_editkeyword($mailcontent_idw) {
    global $user;
    if (user_access('settings actions')) {
        $text = "<hr><br><br>";
        $GLOBALS['mailcontent_idw'] = $mailcontent_idw;
        $GLOBALS['mailcontent_ret'] = 'keywords';
        $text = $text.drupal_get_form('mailcontent_settings_edit_keyword_form');
        $GLOBALS['mailcontent_idw'] = '';
    } else {
        $text = "<hr><br><br>".t("You have not permission for this action!");
        global $user;
        mailcontent_error_permissions("User ".$user->uid." has not permission");
    }
    return $text;
} //OK

/*
 * Funkce pro mazání obsahu - vykreslí formulář
*/
function mailcontent_delmail($mailcontent_idm, $return = '') {
    global $user;
    if (user_access('content edit')) {
        $text = "<hr><br><br>".t('Do you wish delete mail from database?');
        $GLOBALS['mailcontent_idm'] = $mailcontent_idm;
        $GLOBALS['mailcontent_ret'] = $return;
        $text = $text.drupal_get_form('mailcontent_del_mail_form');
        $GLOBALS['mailcontent_idm'] = '';
        $GLOBALS['mailcontent_ret'] = '';
    } else {
        $text = "<hr><br><br>".t("You have not permission for this action!");
        global $user;
        mailcontent_error_permissions("User ".$user->uid." has not permission");
    }
    return $text;
} //OK

/*
 * Funkce pro mazání role - vykreslí formulář
*/
function mailcontent_delrole($mailcontent_idr) {
    global $user;
    if (user_access('settings roles')) {
        if (db_result(db_query("SELECT name FROM {mailcontent_role} WHERE idr=".$mailcontent_idr))) {
            $result = (db_query("SELECT name FROM {mailcontent_role} WHERE idr=".$mailcontent_idr));
            $row = db_fetch_array($result);
        }
        $text = "<hr><br><br>".t('Do you wish delete')." <b><u>".$row['name']."</u></b> ".t('from roles?');
        $GLOBALS['mailcontent_idr'] = $mailcontent_idr;
        $GLOBALS['mailcontent_ret'] = 'roles';
        $text = $text.drupal_get_form('mailcontent_settings_del_role_form');
        $GLOBALS['mailcontent_idr'] = '';
    } else {
        $text = "<hr><br><br>".t("You have not permission for this action!");
        global $user;
        mailcontent_error_permissions("User ".$user->uid." has not permission");
    }
    return $text;
} //OK

/*
 * Funkce pro mazání role - vykreslí formulář
*/
function mailcontent_editrole($mailcontent_idr) {
    global $user;
    if (user_access('settings roles')) {
        $text = "<hr><br><br>";
        $GLOBALS['mailcontent_idr'] = $mailcontent_idr;
        $GLOBALS['mailcontent_ret'] = 'roles';
        $text = $text.drupal_get_form('mailcontent_settings_edit_role_form');
        $GLOBALS['mailcontent_idr'] = '';
    } else {
        $text = "<hr><br><br>".t("You have not permission for this action!");
        global $user;
        mailcontent_error_permissions("User ".$user->uid." has not permission");
    }
    return $text;
} //OK

/*
 * Funkce pro mazání z tabulky servis - vykreslí formulář
*/
function mailcontent_delother($mailcontent_id) {
    global $user;
    if (user_access('Settings - others')) {
        if (db_result(db_query("SELECT name FROM {mailcontent_servis} WHERE id=".$mailcontent_id))) {
            $result = (db_query("SELECT name FROM {mailcontent_servis} WHERE id=".$mailcontent_id));
            $row = db_fetch_array($result);
        }
        $text = "<hr><br><br>".t('Do you wish delete')." <b><u>".$row['name']."</u></b> ".t('from service table?');
        $GLOBALS['mailcontent_id'] = $mailcontent_id;
        $GLOBALS['mailcontent_ret'] = 'others';
        $text = $text.drupal_get_form('mailcontent_settings_del_other_form');
        $GLOBALS['mailcontent_id'] = '';
    } else {
        $text = "<hr><br><br>".t("You have not permission for this action!");
        global $user;
        mailcontent_error_permissions("User ".$user->uid." has not permission");
    }
    return $text;
} //OK

/*
 * Funkce pro editaci tabulky servis - vykreslí formulář
*/
function mailcontent_editother($mailcontent_id) {
    global $user;
    if (user_access('settings others')) {
        $text = "<hr><br><br>";
        $GLOBALS['mailcontent_id'] = $mailcontent_id;
        $GLOBALS['mailcontent_ret'] = 'others';
        $text = $text.drupal_get_form('mailcontent_settings_edit_other_form');
        $GLOBALS['mailcontent_id'] = '';
    } else {
        $text = "<hr><br><br>".t("You have not permission for this action!");
        global $user;
        mailcontent_error_permissions("User ".$user->uid." has not permission");
    }
    return $text;
} //OK

/*
 * Funkce pro mazání článků z titulky - vykreslí formulář
*/
function mailcontent_delnode_for_mail($idm = 0) {
    global $user;
    if (user_access('content edit')) {
        if (db_result(db_query("SELECT idn FROM {mailcontent_mail} WHERE idm=".$idm))) {
            $res = db_query("SELECT idn FROM {mailcontent_mail} WHERE idm=".$idm);
            while ($row = db_fetch_array($res)) {
                node_delete($row['idn']);
                if (mailcontent_db_update_mail_status($idm)) {

                    mailcontent_info(t("Mail (#".$idm.") was unpublished"));
                    return true;
                } else {
                    return false;
                }
            }
        } else {
            return false;
        }
    } else {
        $text = "<hr><br><br>".t("You have not permission for this action!");
        global $user;
        mailcontent_error_permissions("User ".$user->uid." has not permission");
    }
} //OK


?>
